﻿<?php
require("vender.php");

if(isset($_REQUEST["add"]))
{
		$obj=new Register;
		
		$obj->setFirstname($_POST["name"]);
		$obj->setSurname($_POST["surname"]);
		$obj->setCode($_POST["personalCode"]);
		$obj->setTitle($_POST["title"]);
		$obj->setUsername($_POST["username"]);
		$obj->setPassword($_POST["password"]);
		$obj->setAddress($_POST["address"]);
		$obj->setEmail($_POST["email"]);

                $obj->setProvinceID($_POST['province']);
                $obj->setAmphurID($_POST['amphur']);
                $obj->setDistrictID($_POST["district"]);

                //echo "Hello " .$_POST['province'];

		$filename = explode(".",$_FILES["user_image"]["name"]);
		$ext = $filename[1];
		$obj->setPic($ext);
		
	        if($_REQUEST["title"]=="นาย")
		{
			//$obj=new Register;
			$obj->setSex("M");
		}
		else
		{
			$obj->setSex("F");
		}


//echo "Hello " .$_POST['province'];

		$obj->addRecord();



		
}

if(isset($_REQUEST["edit"]))
{
		$obj=new Register;
		
		$obj->setFirstname($_POST["name"]);
		$obj->setSurname($_POST["surname"]);
		$obj->setCode($_POST["personalCode"]);
		$obj->setTitle($_POST["title"]);
		$obj->setUsername($_POST["username"]);
		$obj->setPassword($_POST["password"]);
		$obj->setAddress($_POST["address"]);
		$obj->setEmail($_POST["email"]);

                $obj->setProvinceID("1");
                $obj->setAmphurID("1");
                $obj->setDistrictID("1");

                //echo '$_POST["address"]';

		$filename = explode(".",$_FILES["user_image"]["name"]);
		$ext = $filename[1];
		$obj->setPic($ext);
		
	        if($_REQUEST["title"]=="นาย")
		{
			//$obj=new Register;
			$obj->setSex("M");
		}
		else
		{
			$obj->setSex("F");
		}




		$obj->editRecord();



		
}


if(isset($_REQUEST["username"]))
{
	$obj=new Register;
	if($_GET["username"]!="")
	{
		$obj->setUsername($_GET["username"]);
		$obj->validateUser();
	}else{
		echo "";
	}
}
?>